package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.order.client.OrderFeignClient;
import com.atguigu.gmall.user.client.UserFeignClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class OrderController {
    @Resource
    private UserFeignClient userFeignClient;
    @Resource
    private OrderFeignClient orderFeignClient;
    @GetMapping("/trade.html")
    public String trade(Model model) {
        List<UserAddress> userAddressList = userFeignClient.userAddressList();
        model.addAttribute("userAddressList",userAddressList);
        Map<String, Object> trade = orderFeignClient.trade();
        if (trade != null &&trade.size()>0){
            model.addAllAttributes(trade);
            return "order/trade";
        }
        return "redirect:http://cart.gmall.com/cart.html";
    }
}
